package com.morphiastic.tests.custommapers;

import com.google.code.morphia.converters.TypeConverter;
import com.google.code.morphia.mapping.MappedField;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.vividsolutions.jts.geom.Point;

public class PointConverter extends TypeConverter{
	
	
	public PointConverter(){
		super(Point.class);
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public Object decode(Class targetClass, Object fromDBObject, MappedField optionalExtraInfo){

		
		return new Point(null,null);
	}

	@Override
	public Object encode(Object value, MappedField optionalExtraInfo) {
		
		System.out.println(" ============================ POINTCONVERTER ENCODE HIT ===========================");
		
		
		if (value == null)
			return null;
		Point point = (Point)value;
		
		DBObject dbo = new BasicDBObject();
		dbo.put("latitude", point.getY());
		dbo.put("longitude", point.getX());
		dbo.put("SRID", point.getSRID());
		
		return dbo;
	}
}
